const domain = str=>{
  const {miniProgram} = wx.getAccountInfoSync()
 
  if(miniProgram.envVersion === 'develop'){
    return 'https://bhs-smyj-api.gzmxiong.com'
  }
  return 'https://bhs-smyj-api.gzmxiong.com' 
}

export default {
request:(params)=>{
  wx.request({
    url: domain()+params.url,
    data: params.data,
    method: params.method || 'POST',
    header:{
      ...params.header,
      'Authorization': wx.getStorageSync("token")||undefined,
      'x-client': 'wxApp'
    },
    success:(res)=>{
      if(res.data.code === 200401){
        wx.removeStorageSync('token')
       wx.redirectTo({
         url: '/pages/login/login',
       })
      }else{
        params.success && params.success(res.data)
      }
    },
    fail:(err)=>{
      params.fail && params.fail(err)
    }
  })
}
}